﻿using LibNiconico.NiconicoApi.Lives.Comments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoApiHelperTest.Comments
{
    class TestNicoLiveCommentClient : INicoCommentClient
    {
        private INicoLiveCommentClient commentClient;

        internal TestNicoLiveCommentClient(INicoLiveCommentClient commentClient)
        {
            this.commentClient = commentClient;
            this.commentClient.ChatReceived += onreceived;
            Received = null;
        }

        private void onreceived(NicoLiveCommentClientChatCommentEventArgs args)
        {
            List<NicoChatComment> chatcomments = new List<NicoChatComment>();

            foreach (var readComment in args.ChatComments)
            {
                chatcomments.Add(NicoChatComment.CreateFrom(readComment));
            }

            if (Received != null)
            {
                Received(chatcomments);
            }
        }


        public LibNiconico.NiconicoApi.HeartBeat.INiconicoHeartBeatClient HeartBeatClient
        {
            get { return commentClient.HeartBeatClient; }
        }

        public event Action<IEnumerable<NicoChatComment>> Received;

        public async Task SendAsync(NicoSubmitChatComment comment)
        {
            await this.commentClient.SendAsync(comment.ToLiveSubmitChatComment());
        }

        public void Dispose()
        {
            this.commentClient.Dispose();
        }


        public async Task ConnectAsync()
        {
            await this.commentClient.ConnectAsync();
        }


        public async Task OwnerSendAsync(NicoLiveOwnerChatComment chatComment)
        {
            await this.commentClient.SendOwnerChatCommentAsync(chatComment);
        }
    }
}
